/* SVN FILE: $Id: $ */
/**
 * Short description for file.
 * 
 * jQuery is required
 * jamal is required
 * JamalBuilder:  Javascript MVC Assembler
 * Copyright (c)  2007, Georg Leciejewski <http://blog.mediaprojekte.de/>
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright        Copyright (c) 2006, Georg Leciejewski
 * @link            
 * @package          JamalBuilder
 * @subpackage       jamal.controllers.builds
 * @since            JamalBuilder v 0.1
 * @version          $Revision: $
 * @modifiedby       $LastChangedBy: $
 * @lastmodified     $Date: $
 * @license          http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * SettingsController
 * 
 * controls the settings of the application by reading writing them to a XML file
 *
 */
$j.c({Settings: {
    name: 'SettingsController',
	
	
    /**
     * Build index
     * where you select a folder and build jamal
     */
    index: function () {
    	jamal.log('Start SettingsController index');

		var project_dir = null;
		var use_sound	= null;

		
		$("#settingsForm").submit(function(e) {
				e.preventDefault();
				var data = $('#settingsForm').formToArray();
				$j.m.saveXml(data);
		});	
		
		/*
		var options = {

			success: function(data) {
			 // responseXML is XML document object
			 jamal.log(typeof data);
			 //alert(data);

			}
		};
		$("#settingsForm").ajaxForm(options);	
		*/
    },
	
	
	/**
	 * Show a message in the error msg div
	 * @param {String} msg - the message
	 * @param {String} type - the message type: error, success
	 */
	show_msg: function (msg,type) {
		
		$j.current.close_msg();
		
		switch(type)
		{
			case "error":
				//make error
				$("#msg").addClass('error_msg');
				//append message
				$("#msg").append(msg);
				$("#msg").append('<div id="msg_closer"></div>');
				//show container
				$("#msg").show();
				
			break;
			case "success":
				//make error
				$("#msg").addClass('success_msg');
				//append message
				$("#msg").append(msg);
				//show container
				$("#msg").show();
				
			break;
					
		}
		
		$("#msg").click(function () {
			$j.current.close_msg();
		})
		
	},
	
	/**
	 * closes and cleans the message div
	 */
	close_msg: function () {
		
		$("#msg").removeClass();
		$("#msg").empty();
		$("#msg").hide();
		$("#msg").unbind('click');

	}
	
	
}
});
